<template>
	<view class="user-wallet-yj-page">
		<view class="header-box">
			<view class="bg"></view>
			<image src="../../static/images/bg_3.png" mode="widthFix" class="bg-img"></image>
			<view class="text1">我的押金</view>
			<view style="display: flex;align-items: center;gap: 20rpx;">
				<view class="text2">
					<text class="t">￥</text>{{myWallet.yajin_money}}
				</view>
				<u-button size="medium" shape="circle" @click="jump">提现</u-button>
			</view>
			<view class="text3">
				<u-icon name="volume" size="28" color="#fff"></u-icon>
				<text class="text">押金在商品确认归还/扣除租金后原路退回</text>
			</view>
		</view>
		<view class="main-box">
			<!-- <view class="tab-box">
				<view v-for="v in tabList" :key="v.id" class="tab" :class="{'is-active':v.id==currTab.id}"
					@tap="changeTab(v)">{{v.name}}</view>
			</view> -->

			<view class="list-box">
				<view class="item" v-for="item in dataList" :key="item.id">
					<view class="top-bar">
						<view class="label">{{item.goods.goods_name}}（{{item.name}}）</view>
						<view class="value">+{{item.first_pay_amount}}</view>
					</view>
					<view class="content row-between">
						<!-- <u-icon name="volume" size="28" color="#FF2C3C"></u-icon> -->
						<view class="text">
							租金支付：-{{item.pay_out.order}}
						</view>
						<view class="text">
							平台定损：-{{item.pay_out.pt_ds}}
						</view>
						<view class="text">
							可退押金：{{Number(item.first_pay_amount)-Number(item.pay_out.order)-Number(item.pay_out.pt_ds)}}
						</view>
					</view>
					<view class="footer-bar">
						<view class="date">{{item.create_time}}</view>
						<view class="type">租期：{{item.goods.qi}} | {{item.is_return_confirm}}</view>
					</view>
				</view>
				<loading-footer :status="status"></loading-footer>
			</view>
		</view>
	</view>
</template>

<script>
	import {
		getYaJinList,
		getWallet
	} from '../../../api/user';
	import {
		loadingFun
	} from '../../../utils/tools';
	import {
		loadingType
	} from '../../../utils/type';
	const tabList = [{
		id: 1,
		name: '收支记录'
	}, {
		id: 2,
		name: '消费记录'
	}];
	export default {
		data() {
			return {
				page: 1,
				status: loadingType.LOADING,
				dataList: [],
				tabList: tabList,
				currTab: tabList[0],
				myWallet: null,
			};
		},

		components: {},
		props: {},

		onLoad: function(options) {
			this.getDataList();

			// 获取钱包信息
			getWallet().then(res => {
				if (res.code != 1) return this.$toast({
					title: res.msg
				});
				this.myWallet = res.data;
			})
		},
		onReachBottom() {
			this.getDataList();
		},
		methods: {
			clear() {
				this.page = 1;
				this.status = loadingType.LOADING;
				this.dataList = []
			},
			jump() {
				uni.navigateTo({
					url: '/bundle/pages/user_withdraw/user_withdraw?leixin=1'
				})
			},
			changeTab(v) {
				this.currTab = v;
				this.clear();
				this.getDataList();
			},
			async getDataList() {
				const data = await loadingFun(getYaJinList, this.page, this.dataList, this.status, {
					type: this.currTab.id
				});
				if (data) {
					this.page = data.page;
					this.dataList = data.dataList;
					this.status = data.status;
				}
			}
		}
	};
</script>
<style lang="scss" scoped>
	@import "index.scss";
</style>